<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="文件名称" prop="fileName">
        <el-input
            v-model="queryParams.fileName"
            placeholder="请输入文件名称"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文件路径" prop="filePath">
        <el-input
            v-model="queryParams.filePath"
            placeholder="请输入文件路径"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="本人姓名" prop="patientName">
        <el-input
            v-model="queryParams.patientName"
            placeholder="请输入本人姓名"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参与者电话" prop="phone">
        <el-input
            v-model="queryParams.phone"
            placeholder="请输入参与者电话"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phoneMobile">
        <el-input
            v-model="queryParams.phoneMobile"
            placeholder="请输入手机号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="本人签名图片" prop="qmtp">
        <el-input
            v-model="queryParams.qmtp"
            placeholder="请输入本人签名图片"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="签署时间" prop="qsrq">
        <el-date-picker clearable
                        v-model="queryParams.qsrq"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择签署时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="法定代理人姓名" prop="dlrXm">
        <el-input
            v-model="queryParams.dlrXm"
            placeholder="请输入法定代理人姓名"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理人关系" prop="dlrGx">
        <el-input
            v-model="queryParams.dlrGx"
            placeholder="请输入代理人关系"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理人签名图片" prop="dlrQmtp">
        <el-input
            v-model="queryParams.dlrQmtp"
            placeholder="请输入代理人签名图片"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理人签署原因" prop="dlrQsyy">
        <el-input
            v-model="queryParams.dlrQsyy"
            placeholder="请输入代理人签署原因"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理人签署日期" prop="dlrQsrq">
        <el-date-picker clearable
                        v-model="queryParams.dlrQsrq"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择代理人签署日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="见证人姓名" prop="jzrName">
        <el-input
            v-model="queryParams.jzrName"
            placeholder="请输入见证人姓名"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="见证人签名图片" prop="jzrQmtp">
        <el-input
            v-model="queryParams.jzrQmtp"
            placeholder="请输入见证人签名图片"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="见证人签署原因" prop="jzrQsyy">
        <el-input
            v-model="queryParams.jzrQsyy"
            placeholder="请输入见证人签署原因"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="见证人签署日期" prop="jzrQsrq">
        <el-date-picker clearable
                        v-model="queryParams.jzrQsrq"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择见证人签署日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否同意，0拒绝，1同意" prop="agreed">
        <el-input
            v-model="queryParams.agreed"
            placeholder="请输入是否同意，0拒绝，1同意"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医生签名图片" prop="ysQmtp">
        <el-input
            v-model="queryParams.ysQmtp"
            placeholder="请输入医生签名图片"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医生电话" prop="ysPhone">
        <el-input
            v-model="queryParams.ysPhone"
            placeholder="请输入医生电话"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医生签名日期" prop="ysQmrq">
        <el-date-picker clearable
                        v-model="queryParams.ysQmrq"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择医生签名日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="同意书文件地址" prop="tysPath">
        <el-input
            v-model="queryParams.tysPath"
            placeholder="请输入同意书文件地址"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否删除" prop="deleted">
        <el-input
            v-model="queryParams.deleted"
            placeholder="请输入是否删除"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['keyan:tys:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['keyan:tys:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['keyan:tys:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['keyan:tys:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tysList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="同意书ID" align="center" prop="id"/>
      <el-table-column label="文件名称" align="center" prop="fileName"/>
      <el-table-column label="文件路径" align="center" prop="filePath"/>
      <el-table-column label="本人姓名" align="center" prop="patientName"/>
      <el-table-column label="参与者电话" align="center" prop="phone"/>
      <el-table-column label="手机号" align="center" prop="phoneMobile"/>
      <el-table-column label="本人签名图片" align="center" prop="qmtp"/>
      <el-table-column label="签署时间" align="center" prop="qsrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.qsrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="法定代理人姓名" align="center" prop="dlrXm"/>
      <el-table-column label="代理人关系" align="center" prop="dlrGx"/>
      <el-table-column label="代理人签名图片" align="center" prop="dlrQmtp"/>
      <el-table-column label="代理人签署原因" align="center" prop="dlrQsyy"/>
      <el-table-column label="代理人签署日期" align="center" prop="dlrQsrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dlrQsrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="见证人姓名" align="center" prop="jzrName"/>
      <el-table-column label="见证人签名图片" align="center" prop="jzrQmtp"/>
      <el-table-column label="见证人签署原因" align="center" prop="jzrQsyy"/>
      <el-table-column label="见证人签署日期" align="center" prop="jzrQsrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jzrQsrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否同意，0拒绝，1同意" align="center" prop="agreed"/>
      <el-table-column label="医生签名图片" align="center" prop="ysQmtp"/>
      <el-table-column label="医生电话" align="center" prop="ysPhone"/>
      <el-table-column label="医生签名日期" align="center" prop="ysQmrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ysQmrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="同意书文件地址" align="center" prop="tysPath"/>
      <el-table-column label="是否删除" align="center" prop="deleted"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['keyan:tys:edit']"
          >修改
          </el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['keyan:tys:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改同意书文件内容对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="文件名称" prop="fileName">
          <el-input v-model="form.fileName" placeholder="请输入文件名称"/>
        </el-form-item>
        <el-form-item label="文件路径" prop="filePath">
          <el-input v-model="form.filePath" placeholder="请输入文件路径"/>
        </el-form-item>
        <el-form-item label="本人姓名" prop="patientName">
          <el-input v-model="form.patientName" placeholder="请输入本人姓名"/>
        </el-form-item>
        <el-form-item label="参与者电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入参与者电话"/>
        </el-form-item>
        <el-form-item label="手机号" prop="phoneMobile">
          <el-input v-model="form.phoneMobile" placeholder="请输入手机号"/>
        </el-form-item>
        <el-form-item label="本人签名图片" prop="qmtp">
          <el-input v-model="form.qmtp" placeholder="请输入本人签名图片"/>
        </el-form-item>
        <el-form-item label="签署时间" prop="qsrq">
          <el-date-picker clearable
                          v-model="form.qsrq"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择签署时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="法定代理人姓名" prop="dlrXm">
          <el-input v-model="form.dlrXm" placeholder="请输入法定代理人姓名"/>
        </el-form-item>
        <el-form-item label="代理人关系" prop="dlrGx">
          <el-input v-model="form.dlrGx" placeholder="请输入代理人关系"/>
        </el-form-item>
        <el-form-item label="代理人签名图片" prop="dlrQmtp">
          <el-input v-model="form.dlrQmtp" placeholder="请输入代理人签名图片"/>
        </el-form-item>
        <el-form-item label="代理人签署原因" prop="dlrQsyy">
          <el-input v-model="form.dlrQsyy" placeholder="请输入代理人签署原因"/>
        </el-form-item>
        <el-form-item label="代理人签署日期" prop="dlrQsrq">
          <el-date-picker clearable
                          v-model="form.dlrQsrq"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择代理人签署日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="见证人姓名" prop="jzrName">
          <el-input v-model="form.jzrName" placeholder="请输入见证人姓名"/>
        </el-form-item>
        <el-form-item label="见证人签名图片" prop="jzrQmtp">
          <el-input v-model="form.jzrQmtp" placeholder="请输入见证人签名图片"/>
        </el-form-item>
        <el-form-item label="见证人签署原因" prop="jzrQsyy">
          <el-input v-model="form.jzrQsyy" placeholder="请输入见证人签署原因"/>
        </el-form-item>
        <el-form-item label="见证人签署日期" prop="jzrQsrq">
          <el-date-picker clearable
                          v-model="form.jzrQsrq"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择见证人签署日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否同意，0拒绝，1同意" prop="agreed">
          <el-input v-model="form.agreed" placeholder="请输入是否同意，0拒绝，1同意"/>
        </el-form-item>
        <el-form-item label="医生签名图片" prop="ysQmtp">
          <el-input v-model="form.ysQmtp" placeholder="请输入医生签名图片"/>
        </el-form-item>
        <el-form-item label="医生电话" prop="ysPhone">
          <el-input v-model="form.ysPhone" placeholder="请输入医生电话"/>
        </el-form-item>
        <el-form-item label="医生签名日期" prop="ysQmrq">
          <el-date-picker clearable
                          v-model="form.ysQmrq"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择医生签名日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="同意书文件地址" prop="tysPath">
          <el-input v-model="form.tysPath" placeholder="请输入同意书文件地址"/>
        </el-form-item>
        <el-form-item label="是否删除" prop="deleted">
          <el-input v-model="form.deleted" placeholder="请输入是否删除"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listTys, getTys, delTys, addTys, updateTys} from "@/api/keyan/tys";

export default {
  name: "Tys",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 同意书文件内容表格数据
      tysList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fileName: null,
        filePath: null,
        patientName: null,
        phone: null,
        phoneMobile: null,
        qmtp: null,
        qsrq: null,
        dlrXm: null,
        dlrGx: null,
        dlrQmtp: null,
        dlrQsyy: null,
        dlrQsrq: null,
        jzrName: null,
        jzrQmtp: null,
        jzrQsyy: null,
        jzrQsrq: null,
        agreed: null,
        ysQmtp: null,
        ysPhone: null,
        ysQmrq: null,
        tysPath: null,
        deleted: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fileName: [
          {required: true, message: "文件名称不能为空", trigger: "blur"}
        ],
        filePath: [
          {required: true, message: "文件路径不能为空", trigger: "blur"}
        ],
        patientName: [
          {required: true, message: "本人姓名不能为空", trigger: "blur"}
        ],
        tysPath: [
          {required: true, message: "同意书文件地址不能为空", trigger: "blur"}
        ],
        deleted: [
          {required: true, message: "是否删除不能为空", trigger: "blur"}
        ],
        createBy: [
          {required: true, message: "操作人ID不能为空", trigger: "blur"}
        ],
        createTime: [
          {required: true, message: "创建时间不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询同意书文件内容列表 */
    getList() {
      this.loading = true;
      listTys(this.queryParams).then(response => {
        this.tysList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fileName: null,
        filePath: null,
        patientName: null,
        phone: null,
        phoneMobile: null,
        qmtp: null,
        qsrq: null,
        dlrXm: null,
        dlrGx: null,
        dlrQmtp: null,
        dlrQsyy: null,
        dlrQsrq: null,
        jzrName: null,
        jzrQmtp: null,
        jzrQsyy: null,
        jzrQsrq: null,
        agreed: null,
        ysQmtp: null,
        ysPhone: null,
        ysQmrq: null,
        tysPath: null,
        deleted: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加同意书文件内容";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTys(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改同意书文件内容";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTys(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTys(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除同意书文件内容编号为"' + ids + '"的数据项？').then(function () {
        return delTys(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('keyan/tys/export', {
        ...this.queryParams
      }, `tys_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
